﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.gates {
    import flash.utils.*;
    import Classes.*;

    public class GateFactory {

        private var m_registeredGates:Dictionary;

        public function GateFactory(){
            this.m_registeredGates = new Dictionary();
        }
        public function cleanUp():void{
            var _local1:Object;
            if (this.m_registeredGates){
                for (_local1 in this.m_registeredGates) {
                    delete this.m_registeredGates[_local1];
                };
            };
            this.m_registeredGates = null;
        }
        private function createGate(_arg1:String, _arg2:String, _arg3:Number):IGate{
            var _local4:IGate;
            var _local5:Class = (this.m_registeredGates[_arg1] as Class);
            if (_local5){
                _local4 = new _local5(_arg2);
                _local4.targetObjectId = _arg3;
            };
            return (_local4);
        }
        public function register(_arg1:String, _arg2:Class):void{
            this.m_registeredGates[_arg1] = _arg2;
        }
        public function loadGateFromXML(_arg1:Item, _arg2:ItemInstance, _arg3:String, _arg4:Function):IGate{
            var _local7:XML;
            var _local8:String;
            var _local5:IGate;
            var _local6:XMLList = _arg1.gatesXml["gate"];
            for each (_local7 in _local6) {
                if (_local7.@name == _arg3){
                    _local8 = ((_local7.@type) || (GateType.INVENTORY));
                    _local5 = this.createGate(_local8, _arg1.name, _arg2.getId());
                    _local5.loadFromXML(_local7);
                    _local5.unlockCallback = _arg4;
                    break;
                };
            };
            return (_local5);
        }
        public function loadGateFromObject(_arg1:Object, _arg2:Item, _arg3:ItemInstance, _arg4:Function):IGate{
            var _local6:Object;
            var _local7:String;
            var _local5:IGate;
            if (_arg1.gates){
                for each (_local6 in _arg1.gates) {
                    _local7 = ((_local6.type) || (GateType.INVENTORY));
                    _local5 = this.createGate(_local7, _arg2.name, _arg3.getId());
                    _local5.loadFromObject(_local6);
                    _local5.unlockCallback = _arg4;
                };
            };
            return (_local5);
        }

    }
}//package Classes.gates 
